#include <stdio.h>
#include <stdint.h>

union endian_check {
    uint32_t value;
    uint8_t bytes[4];
};

void debug_techniques() {
    printf("=== 调试技巧 ===\n");
    
    // 方法1：使用联合体
    union endian_check checker;
    checker.value = 0x12345678;
    
    printf("联合体检查:\n");
    printf("  值: 0x%08x\n", checker.value);
    printf("  字节: [0]=0x%02x, [1]=0x%02x, [2]=0x%02x, [3]=0x%02x\n",
           checker.bytes[0], checker.bytes[1], 
           checker.bytes[2], checker.bytes[3]);
    
    // 方法2：指针类型转换
    uint32_t test_value = 0x12345678;
    uint8_t* byte_ptr = (uint8_t*)&test_value;
    
    printf("指针检查:\n");
    for (int i = 0; i < 4; i++) {
        printf("  地址 %p: 0x%02x\n", (void*)(byte_ptr + i), byte_ptr[i]);
    }
    
    // 方法3：编译时检查
    #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
        printf("编译时确定: 小端序系统\n");
    #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
        printf("编译时确定: 大端序系统\n");
    #else
        printf("编译时确定: 字节序未知\n");
    #endif
    printf("\n");
}

int main() {
    debug_techniques();
    return 0;
}
